home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #ifndef SHIP_H
- #define SHIP_H
-
- #include "comm.h"
- #include <Inventor/SbLinear.h>
- class SoSeparator;
- class SoTransform;
- class SoTranslation;
- class SoRotation;
- class SoSwitch;
- class SoMaterial;
- class SoCoordinate3;
-
- #define TURRETRADIUS 1.0 // 1 meter
- #define BEAMRADIUS 0.2 // 20 cm
-
- struct Ray { // 3D ray
- public:
- SbVec3f o; // origin of ray
- SbVec3f d; // direction of ray
- };
-
- class ShipObject {
- public:
- enum Shield { FrontShield = 0, RearShield = 1,
- LeftShield = 2, RightShield = 3,
- TopShield = 4, BottomShield = 5 };
-
- ShipObject(NetId, Team, const char* callSign);
- virtual ~ShipObject();
-
- Team team() const; // return my team
- char* name() const; // return my name
- int score() const; // my score
- int won() const; // number of wins
- int lost() const; // number of losses
- Team flag() const; // which flag I have
- void flag(Team); // set which flag I have
- virtual ShipClass shipClass() const = 0; // ship's class id
- NetId id() const; // host id of ship
-
- SoSeparator* root() const; // return root of ship scene
- void reset(); // reset ship
- void advance(float dt); // step stuff in time (dt sec)
-
- // general ship info
- ShipInfo& shipInfo(); // get ship information
- virtual float mass() const; // mass of ship (kg)
- int exploding() const; // TRUE if blowing up
- float explodeTime() const; // fraction completed
- Active active() const; // return activity state
- void active(Active); // set active state
- int hittable() const; // active and not exploding
- float shipBound() const; // radius of bounding sphere
- int shipVisibility() const; // return ship visibility
- void shipVisibility(int); // set ship visibilty
-
- // get position, orientation, and velocities
- SbVec3f position() const; // get ship position
- const SbRotation& orientation() const; // get ship orientation
- const SbVec3f direction() const; // get ship direction
- SbVec3f velocity() const; // get ship velocity
- virtual float angularAccel() const; // ang. acceleration (rad/s/s)
-
- // set position, orientation, and velocities
- void position(const SbVec3f&);
- void orientation(const SbRotation&);
- void velocity(const SbVec3f&);
- void targetAngVel(const SbVec3f&);
-
- // engines
- void engineOutput(float); // fraction max output (0-1)
- float engineOutput() const; // fraction max output (0-1)
- float engineForce() const; // force from engines (N)
- virtual float engineMaxForce() const; // maximum engine force (N)
- virtual float engineResponse() const; // max output change per second
- float fuelLeft() const; // remaining fuel (frac max)
- void fuelLeft(float); // set remaining fuel
- virtual float fuelRate() const; // fuel/sec at max thrust
-
- // shields
- float shield(Shield) const; // energy protection (J)
- virtual float shieldMaximum() const; // maximum shield strength (J)
- virtual float shieldRecovery() const; // protection recovery (J/s)
- void shieldStrength(float); // set shield strength
-
- // weapons
- int fireMissile(ObjectInfo*); // return TRUE if fired
- int numMissiles() const; // missiles left on board
- void numMissiles(int); // set number of missiles
- virtual int maxMissiles() const; // max missiles ship holds
- ObjectInfo& missileInfo(int); // get missile info
- virtual float missileEnergy() const; // energy from explosion (J)
- float missileRadius() const; // radius of detonation
- float missileBound() const; // bounding sphere radius
- int missileHittable(int) const; // active, !exploding
- int missileVisibility(int n) const; // return visiblity
- void missileVisibility(int n, int); // set missile visiblity
- int missileReady() const; // TRUE if can fire
-
- int fireLaser(); // return TRUE if fired
- float laserHeat() const; // laser overheat (frac max)
- virtual float laserPower() const; // laser power (J/s)
- SbVec3f laserPosition() const; // laser position (world)
- SbVec3f laserDirection() const; // laser direction (world)
- const SbVec3f& turretPosition() const; // laser position (local)
- const SbVec3f& trackDirection() const; // laser direction (local)
- void trackDirection(const SbVec3f&); // set target direction
-
- // hit detection
- float laserHitShip(const Ray&) const;
- float laserHitMissile(const Ray&, int n) const;
- float laserHitAsteroid(const Ray&, int a) const;
- float missileHitShip(const Ray&, float radius) const;
- float missileHitMissile(const Ray&, float rad, int n) const;
- float missileHitAsteroid(const Ray&, float rad, int a) const;
-
- // damage
- void hitShield(const SwHitMessage&);
- void explodeShip(InAddr killer);
- void explodeMissile(const SwHitMessage&);
-
- // flags
- void dropFlag();
- void grabFlag(Team);
-
- // communication
- void read(const ShipInfo&); // set me according to info
-
- // utility functions
- void findWorldDirection(const SbVec3f&, SbVec3f&) const;
- void findWorldPosition(const SbVec3f&, SbVec3f&) const;
- void findLocalDirection(const SbVec3f&, SbVec3f&) const;
- void findLocalPosition(const SbVec3f&, SbVec3f&) const;
- void findLocalPosition(float p[3], SbVec3f&) const;
-
- protected:
- void init(SoSeparator* shipGeometry,
- SoSeparator* shipChangingGeometry,
- const SbVec3f& laserTurretPosition,
- const SbVec3f& flagPosition,
- const SbVec3f& cockpitPosition);
- virtual void advanceExtra(float dt); // advance ship specific stuff
- virtual void newEngineOutput() = 0; // change engine geometry
- virtual SbVec3f missileSource(int) const = 0; // missile start pos
- virtual int missileSilos() const = 0; // number missile silos
-
- private:
- SoSeparator* makeLaserTurret();
- SoSeparator* makeLaserBeam();
- SoSeparator* makeShields();
-
- void advanceCamera();
- void advancePosition(float dt);
- void advanceOrientation(float dt);
- void advanceEngine(float dt);
- void advanceShield(float dt);
- void advanceMissile(int, float dt);
- void advanceLaser(float dt);
- void advanceTurn(const SbVec3f&, SbVec3f&,
- float maxAcc, float dt) const;
- Shield shieldNumber(const SbVec3f& i) const;
- float dissipate(float d) const;
-
- private:
- Team myTeam; // which team I'm on
- char* myName; // my call sign
- ShipInfo info;
- SbVec3f cockpit; // cockpit position
- SbRotation rotation; // ship orientation
- SbMatrix rotateMatrix; // rotation matrix
- SbVec3f angularVelDir; // angular velocity
- SbVec3f angularVelDirTarget; // target angularVelDir
- SbVec3f trackingDirection; // direction laser is pointing
- SbVec3f trackingDirTarget; // target trackingDirection
- SbVec3f flagPosition; // position of flags
- float engineOutputTarget; // target for engineOutput
- float fuel; // remaining fuel
- ObjectInfo* missileTarget[MAXMISSILES]; // missile targets
- int missilesLeft; // remaining missiles
- float missileTime[MAXMISSILES];
- float laserTime; // time to show laser beam for
- float laserTemp; // >1 is overheated
- float sx, sy, sz; // ship center
- float sdx, sdy, sdz; // ship size
- float sbs; // ship bounding sphere radius
- float mdx, mdy, mdz; // missile size
- float mbs; // missile bounding radius
- int shipVisible,
- missileVisible[MAXMISSILES];
- int nextSilo; // next silo to shoot from
- int cantGrabFlag[NUMTEAMS]; // prevent immediate re-grab
-
- SoSeparator* wholeShip; // root node of all ship stuff
- SoSwitch* activeSwitch; // show/hide all ship stuff
- SoSwitch* shipSwitch; // show/hide ship
- SoTranslation* shipPosition; // ship position node
- SoRotation* shipOrientation; // ship orientation node
- SoSwitch* missileSwitch[MAXMISSILES]; // show/hide missile
- SoTranslation* missilePosition[MAXMISSILES];
- SoRotation* missileOrientation[MAXMISSILES];
- SoSwitch* laserSwitch; // laser beam on/off switch
- SoTranslation* laserLocation; // laser translation node
- SoRotation* laserOrientation; // laser rotation node
- SoSwitch* hitSwitch[MAXHITS]; // turn shield hits on/off
- SoMaterial* hitMaterial[MAXHITS]; // hit shading
- SoTransform* hitTransform[MAXHITS]; // location of hit on shield
- SoCoordinate3* beamCoord; // laser beam geometry
- SoSwitch* flagSwitch; // choose which flag visible
-
- float laserBeamPoints[10][3]; // vertices for laser beam
-
- static SoSeparator* missileGeom; // missile object
- };
-
- // Once a ship is added to the array or missile added to ship's missile array
- // it must not move from that position in the list. Otherwise the
- // missileTarget entry will start pointing to the wrong thing.
-
- // reset() *must* be called after construction.
-
- #endif
-